package com.example.design.pattern.behavior.command;

import java.util.concurrent.LinkedBlockingQueue;

public class Invoker {

    private LinkedBlockingQueue<Command> commandQueue = new LinkedBlockingQueue<>();
    
    public void addCommand(Command command) {
        commandQueue.add(command);
    }
    
    public void execute() {
        Command command = null;
        do {
            command = commandQueue.poll();
            if (command != null) {
                command.execute();
            }
        } while (command != null);
    }
}
